package com.store.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */
public class MySpinnerAdapter extends BaseAdapter {

    List<String> mList = new ArrayList<String>();
    Context mContext;

    public MySpinnerAdapter(Context context, List list) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        if (mList != null) {
            return mList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        if (mList != null) {
            return mList.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View convertView = inflater.inflate(R.layout.item_spinner, null);

        if (convertView != null) {
            TextView tv = (TextView) convertView.findViewById(R.id.spinner_tv);
            tv.setText(mList.get(i));
        }
        return convertView;
    }

}
